/*
 * @Author: Kilims Ye
 * @LastEditors: Kilims Ye
 * @Date: 2020-06-30 21:37:21
 * @LastEditTime: 2021-03-31 09:46:34
 * @Description:BorrowMoneyDetailPage
 */
import React, { Suspense, lazy } from "react";
import SkeletonLoading from "@components/SkeletonLoading";
import { Router, Route, Redirect } from "react-router-dom";
import CacheRoute, { CacheSwitch } from "react-router-cache-route";
import history from "./history.js";
import { retry } from "@utils/UtilsFunc";

const DemoPage = lazy(() => retry(() => import("../pages/DemoPage")));

const routeName = process.env.REACT_APP_ROUTE_NAME;

const routesList = [
  {
    path: "DemoPage",
    Component: DemoPage,
    Route: Route,
  }
];

const Routes = () => {
  return (
    <Router history={history}>
      <Suspense fallback={<SkeletonLoading />}>
        <CacheSwitch>
          {routesList.map((item, index) => {
            return (
              <item.Route
                key={index}
                path={`/${routeName}/${item.path}`}
                exact
                render={(props) => (
                  <item.Component {...props} />
                )}
              />
            );
          })}
          {/** 重定向 */}
          <Redirect to={`/${routeName}/DemoPage`} />
        </CacheSwitch>
      </Suspense>
    </Router>
  );
};

export default Routes;
